#!/bin/sh -e
#
#    logo: determine which logo to use
#
#    Copyright (C) 2008 Canonical Ltd.
#    Copyright (C) 2011-2023 Dustin Kirkland
#
#    Authors: Dustin Kirkland <kirkland@byobu.org>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, version 3 of the License.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

__logo_detail() {
	MARKUP="false"
	__logo
}

__logo() {
	local logo=
	if [ -n "$LOGO" ]; then
		# Allow users to define their own logo in $BYOBU_CONFIG_DIR/status
		printf "%s" "$LOGO"
		return
	fi
	local distro="$(printf "%s" "$BYOBU_DISTRO" | $BYOBU_SED 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')"
	case "$distro" in
		*ubuntu*)
			if $MARKUP; then
				if [ "$BYOBU_BACKEND" = "tmux" ] && [ "$BYOBU_CHARMAP" = "UTF-8" ]; then
					if [ ! "$VTE_CJK_WIDTH" = "1" ] && [ !  "$VTE_CJK_WIDTH" = "wide" ] ; then
						# color "colour202" "colour255" ; printf " u "; color -
						# Ubuntu's logo doesn't display anywhere, except for on Ubuntu itself, which has the Ubuntu font with the logo
						# which breaks when you ssh into Ubuntu from elsewhere (Windows, Debian, Mac)
						color "colour202" "colour255" ; printf " u "; color -
					else
						color m W; printf " u "; color -
					fi
				else
					color m W; printf " u "; color -
				fi
			else
				printf " u "
			fi
		;;
		*alpine*)
			logo=" /\\\\\\\\ "
			$MARKUP && printf "$(color b b W)%s$(color -)" "$logo" || printf "$logo"
		;;
		*altlinux*)
			logo="alt"
			$MARKUP && printf "$(color Y k)%s$(color -)" "$logo" || printf "$logo"
		;;
	 	*arch*)
			logo=" A "
			$MARKUP && printf "$(color b w b)%s$(color -)" "$logo" || printf "$logo"
		;;
		*centos*)
			if [ "$BYOBU_BACKEND" = "tmux" ] && [ "$BYOBU_CHARMAP" = "UTF-8" ]; then
				logo="※ "
				$MARKUP && printf "$(color w m)※ $(color -)" || printf "$logo"
			else
				$MARKUP && printf "$(color g w)*$(color -)$(color m w)*$(color -)$(color y w)*$(color -)$(color b w)*$(color -)" || printf "$logo"
			fi
		;;
		*debian*)
			logo=" @ "
			$MARKUP && printf "$(color w r)%s$(color -)" "$logo" || printf "$logo"
		;;
		*fedora*)
			logo=" f "
			$MARKUP && printf "$(color b w)%s$(color -)" "$logo" || printf "$logo"
		;;
		*foresight*)
			logo="<@>"
			$MARKUP && printf "$(color b W g)%s$(color -)" "$logo" || printf "$logo"
		;;
		*gentoo*)
			logo=" > "
			$MARKUP && printf "$(color b c w)%s$(color -)" "$logo" || printf "$logo"
		;;
		*glinux*)
			logo=" G "
			# Green: 3cba54=71, Yellow: f4c20d=214, Red: db3236=167, Blue: 4885ed=69
			$MARKUP && printf "$(color colour0 colour69)██$(color colour0 colour167)■$(color colour0 colour214)■$(color colour0 colour69)▄$(color colour0 colour71)█$(color colour0 colour167)■$(color -)" || printf "$logo"
		;;
		*mac*|*darwin*)
			if [ "$BYOBU_BACKEND" = "tmux" ] && [ "$BYOBU_CHARMAP" = "UTF-8" ]; then
				# The Apple option character
				#logo=" ⌘  "
				# The Apple logo -- only visible from Mac terminals
				logo="  "
			else
				logo=" X "
			fi
			$MARKUP && printf "$(color w k)%s$(color -)" "$logo" || printf "$logo"
		;;
		*mandriva*)
			logo=" (* "
			$MARKUP && printf "$(color b k c) ($(color -)$(color b k y)*$(color -) " || printf "$logo"
		;;
		*mint*)
			logo=" lm "
			$MARKUP && printf "$(color g w)$logo$(color -)$(color g w)$(color -) " || printf "$logo"
		;;
		*openwrt*)
			logo="OWrt"
			$MARKUP && printf "$(color b colour66 W)%s$(color -)" "$logo" || printf "$logo"
		;;
		*raspbian*)
			logo=" @ "
			$MARKUP && printf "$(color colour125 colour15)%s$(color -)" "$logo" || printf "$logo"
		;;
		*red*hat*|*rhel*)
			logo=" RH "
			$MARKUP && printf "$(color R k)%s$(color -)" "$logo" || printf "$logo"
		;;
		*rockhopper*)
			logo="palm"
			$MARKUP && printf "$(color k w)%s$(color -)" "$logo" || printf "$logo"
		;;
		*slackware*)
			logo=".S "
			$MARKUP && printf "$(color u B k)%s$(color -)" "$logo" || printf "$logo"
		;;
		*suse*)
			logo="SUSE"
			$MARKUP && printf "$(color W g)%s$(color -)" "$logo" || printf "$logo"
		;;
		*wolfi*)
			logo=" * "
			$MARKUP && printf "$(color m W)%s$(color -)" "$logo" || printf "$logo"
		;;
		*xandros*)
			logo=" X "
			$MARKUP && printf "$(color W r)%s$(color -)" "$logo" || printf "$logo"
		;;
		*)
			if [ "$BYOBU_BACKEND" = "tmux" ] && [ "$BYOBU_CHARMAP" = "UTF-8" ]; then
				logo="〣"
			else
				logo="[B]"
			fi
			$MARKUP && printf "$(color b k W)%s$(color -)" "$logo" || printf " $logo "
		;;
	esac
	printf " "
}

# vi: syntax=sh ts=4 noexpandtab
